package org.jeecg.modules.system.mapper;

import java.util.List;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.entity.SysUserRole;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

/**
 * <p>
 * 用户角色表 Mapper 接口
 * </p>
 *
 * @Author scott
 * @since 2018-12-21
 */
public interface SysUserRoleMapper extends BaseMapper<SysUserRole> {

	@Select("select role_code from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
	List<String> getRoleByUserName(@Param("username") String username);

	@Select("select id from sys_role where id in (select role_id from sys_user_role where user_id = (select id from sys_user where username=#{username}))")
	List<String> getRoleIdByUserName(@Param("username") String username);

	@Select("select * from sys_user where (username =#{username} or id  in (#{id}) )and del_flag=0")
	List<SysUser> getRoleByUserNames(@Param("username") String username, @Param("id") List<String> id);


	@Select("<script>"
			+"select id,realname from sys_user where del_flag=0 and `status`=1 and type=#{thirdType} and create_by=#{create_by}"
			+ "<if test='ids!=null'>"
			+ " and rel_tenant_ids=#{ids}"
			+ "</if>"
			+ "</script>" )
	List<SysUser> selectSysUser(@Param("create_by") String create_by,@Param("ids") String ids,@Param("thirdType")String  thirdType 	);


	@Select("select * from sys_user where (username =#{username}  )and del_flag=0")
	SysUser selectOnes(@Param("username") String username);
}
